//
//  PhotoSelectView.m
//  Weather
//
//  Created by 赵进雄 on 15/3/9.
//  Copyright (c) 2015年 feinno. All rights reserved.
//

#import "PhotoSelectView.h"


#define MF_ColorFromRGB(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]

@implementation PhotoSelectView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        UIButton *photoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        photoBtn.frame = CGRectMake(10, 20, 111, 111);
        photoBtn.layer.masksToBounds = YES;
        photoBtn.layer.cornerRadius = 60.f;
        [photoBtn setImage:[UIImage imageNamed:@"icon_camara.png"] forState:UIControlStateNormal];
       
        [photoBtn setTitle:@"拍照" forState:UIControlStateNormal];
        [photoBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
        [photoBtn setTitleEdgeInsets:UIEdgeInsetsMake(110, -110,20, 0)];
        [photoBtn setImageEdgeInsets:UIEdgeInsetsMake(27, 27, 27, 27)];
        [photoBtn setTitleColor:MF_ColorFromRGB(181, 181, 181) forState:UIControlStateNormal];
        [photoBtn setTitleColor:MF_ColorFromRGB(14, 82, 129) forState:UIControlStateHighlighted];
        photoBtn.backgroundColor = [UIColor clearColor];
        [photoBtn addTarget:self action:@selector(camaraClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:photoBtn];
        
        UIButton *selectPhotoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        selectPhotoBtn.frame = CGRectMake(photoBtn.frame.size.width+photoBtn.frame.origin.x + 6,20, 111, 111);
        selectPhotoBtn.layer.masksToBounds = YES;
        selectPhotoBtn.layer.cornerRadius = 60.f;
        [selectPhotoBtn setImage:[UIImage imageNamed:@"icon_local.png"] forState:UIControlStateNormal];
        [selectPhotoBtn setTitle:@"本地" forState:UIControlStateNormal];
        [selectPhotoBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
        [selectPhotoBtn setTitleEdgeInsets:UIEdgeInsetsMake(110, -110,20, 0)];
        [selectPhotoBtn setImageEdgeInsets:UIEdgeInsetsMake(27, 27, 27, 27)];
        [selectPhotoBtn setTitleColor:MF_ColorFromRGB(181, 181, 181) forState:UIControlStateNormal];
        [selectPhotoBtn setTitleColor:MF_ColorFromRGB(14, 82, 129) forState:UIControlStateHighlighted];
        selectPhotoBtn.backgroundColor = [UIColor clearColor];
        [selectPhotoBtn addTarget:self action:@selector(photoClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:selectPhotoBtn];
    }
    return self;
}

- (void)camaraClick:(UIButton *)sender
{
    if ([_delegate respondsToSelector:@selector(camaraSelect)]) {
        [_delegate camaraSelect];
    }
}

- (void)photoClick:(UIButton *)sender
{
    if ([_delegate respondsToSelector:@selector(photoSelect)]) {
        [_delegate photoSelect];
    }
}


@end
